//
//  AccountManager.m
//  zaipin
//
//  Created by whj on 16/10/20.
//  Copyright © 2016年 master. All rights reserved.
//

#import "AccountManager.h"
#import "AccountInfoModel.h"
#define AccountFilepath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"account.data"]

@implementation AccountManager

+(void)userLogout{
    AccountInfoModel *currentUser = kCurrentAccount;
  
    [ClassSelf save:currentUser withLoginStatus:NO];
}

/**
 *  存储帐号
 */
+ (void)save:(AccountInfoModel *)account{
    // 归档
    [NSKeyedArchiver archiveRootObject:account toFile:AccountFilepath];
}

+ (void)save:(AccountInfoModel *)account withLoginStatus:(BOOL )loginStatu
{
    // 归档
    account.login = loginStatu;
    BOOL bol =  [NSKeyedArchiver archiveRootObject:account toFile:AccountFilepath];
    if (bol) {
        NSLog(@"保存--OK");
    }else{
        NSLog(@"保存--Error");
    }
}

/**
 *  读取帐号,该账号是当前用户的账号
 */
+ (AccountInfoModel *)account{
    // 读取帐号
    AccountInfoModel *account = [NSKeyedUnarchiver unarchiveObjectWithFile:AccountFilepath];
    return account;
}


@end
